package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.impl.DishServiceImpl;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "菜品相关接口")
@RestController
@RequestMapping("/admin/dish")
public class DishController {

    @Autowired
    private DishServiceImpl dishService;

    /**
     * 添加菜品
     *
     * @param dishDTO
     * @return
     */
    @ApiOperation("添加菜品")
    @PostMapping
    public Result<String> addDish(@RequestBody DishDTO dishDTO) {
        dishService.addDish(dishDTO);
        return Result.success("添加菜品成功！");
    }

    /**
     * 菜品的分页查询
     */
    @ApiOperation("菜品分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        return Result.success(dishService.page(dishPageQueryDTO));
    }


    /**
     * 菜品的分页查询
     */
    @ApiOperation("菜品分页查询")
    @GetMapping("/list")
    public Result<List<Dish>> list(Dish dish) {
        return Result.success(dishService.list(dish));
    }

    /**
     *
     */
    @ApiOperation("批量删除菜品")
    @DeleteMapping
    public Result<String> deleteDish(@RequestParam Long[] ids) {
        dishService.deleteDish(ids);
        return Result.success("删除菜品成功！");
    }

    /**
     * 菜品起售、停售
     */
    @ApiOperation("菜品状态修改")
    @PostMapping("/status/{status}")
    public Result<String> statusDish(@PathVariable Integer status, @RequestParam Long id) {
        dishService.statusDish(status, id);
        return Result.success("菜品状态已修改！");
    }

    /**
     * 根据id查询菜品
     */
    @ApiOperation("根据id查询指定菜品")
    @GetMapping("/{id}")
    public Result<DishVO> getDish(@PathVariable Long id) {
        return Result.success(dishService.getDish(id));
    }

    /**
     * 修改菜品
     */
    @ApiOperation("修改菜品")
    @PutMapping
    public Result<String> updateDish(@RequestBody DishDTO dishDTO) {
        dishService.updateDish(dishDTO);
        return Result.success("修改菜品成功！");
    }
}
